package com.qf.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.blog.auth.LoginThreadLocal;
import com.qf.blog.entity.Comment;
import com.qf.blog.entity.DiscussPost;
import com.qf.blog.mapper.CommentMapper;
import com.qf.blog.service.ICommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.blog.vo.CommentVo;
import com.qf.blog.vo.PostVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author toString
 * @since 2024-05-23
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {

    @Autowired
    private FollowerService followerService;

    @Override
    public List<CommentVo> getCommentListByPostId(DiscussPost  post) {
        Integer total= 0;
        List<CommentVo> commentVos = baseMapper.getCommentListByPostId(1,post.getId());
        total = commentVos.size();
        for (CommentVo commentVo : commentVos) {
            //评论点在数量
            Long startsCount = followerService.getStartCount(2, commentVo.getComment().getId());
            commentVo.setStarCount(startsCount);

            //Integer loginUserId = LoginThreadLocal.get().getId();
            Integer isStars = followerService.IsStars(2, commentVo.getComment().getId());
            commentVo.setIsStart(isStars);

            List<CommentVo> replyList = baseMapper.getCommentListByPostId(2, commentVo.getComment().getId());
            commentVo.setReplyVos(replyList);
            total += replyList.size();
        }
        post.setCommentCount(total);
        return commentVos;
    }
}
